<!--过滤组件数值区间-->
<template>
    <div class="umInterval-component">
        <span>数值区间</span>
        <div style="display: inline-block">
            <el-input size="mini" v-input-number.float v-model="tempMinvalue" style="width: 100px" clearable placeholder="左区间"></el-input>
            <span style="color: #999"> — </span>
            <el-input size="mini" v-input-number.float v-model="tempMaxvalue" style="width: 100px" clearable placeholder="右区间"></el-input>
            <el-button v-if="parameter.status==='1'" size="mini" @click="getNumValue">确定</el-button>
        </div>
        <span>{{validateMsg}}</span>
    </div>
</template>

<script>
    import ajax from '@api/ajax'
    import {SAVE_FILTER_INFO} from '@api/url'
    const errMsg = '数值输入不符合规定！'
    export default {
        name: 'NumIntervalComponent',
        data () {
            return {
                validateMsg: null,
                draggableFlag: false,
                tempMinvalue: null,
                tempMaxvalue: null
            }
        },
        props: {
            numIntervalValue: {
                type: Object
            },
            numStatus: {
               type: String
            },
            parameter: {
                type: Object,
                default () {
                    return {
                        status: '0',
                        ctlUnit:''
                    }
                }
            }
        },
        watch: {
           tempMinvalue () {
               console.info(this.numIntervalValue)
               let temp = null
               if (this.numIntervalValue !== null) {
                   debugger
                   temp = JSON.parse(this.numIntervalValue.value).minValue
               }
               return temp
           },
           tempMaxvalue () {
               let temp = null
               if (this.numIntervalValue !== null) {
                   temp = JSON.parse(this.numIntervalValue.value).maxValue
               }
               return temp
           }
        },
        methods: {
            // minValueValidator () {
            //     if (this.tempMaxvalue) {
            //         if (this.tempMinvalue > this.tempMaxvalue) {
            //             this.validateMsg = errMsg
            //         } else {
            //             this.validateMsg = null
            //         }
            //     } else {
            //         this.validateMsg = null
            //     }
            // },
            // maxValueValidator () {
            //     if (this.tempMinvalue) {
            //         if (this.tempMaxvalue < this.tempMinvalue) {
            //             this.validateMsg = errMsg
            //         } else {
            //             this.validateMsg = null
            //         }
            //     } else {
            //         this.validateMsg = null
            //     }
            // },
            getNumValue () {
                if (this.numStatus !== '1') {
                    this.numIntervalValue.optMode = 'U'
                    // 将对应图形组件的id传进去
                    this.numIntervalValue.ctlUnit = this.parameter.ctlUnit
                    let tempObject = JSON.parse(this.numIntervalValue.value)
                    tempObject.minValue = this.tempMinvalue
                    tempObject.maxValue = this.tempMaxvalue
                    this.numIntervalValue.value = JSON.stringify(tempObject)
                    ajax.post(SAVE_FILTER_INFO, this.numIntervalValue).then(res => {
                        this.$emit('getNumFlag')
                    })
                } else {
                    let param = {
                        minValue: this.tempMinvalue,
                        maxValue: this.tempMaxvalue
                    }
                    this.$emit('getNumValue', param)
                }
            },
            clearInput () {
                this.tempMinvalue = null
                this.tempMaxvalue = null
            },
            setInputValue (item) {
                this.tempMinvalue = JSON.parse(item.value).minValue
                this.tempMaxvalue = JSON.parse(item.value).maxValue
            }

        },
        mounted () {
            this.tempMinvalue = JSON.parse(this.numIntervalValue.value).minValue
            this.tempMaxvalue = JSON.parse(this.numIntervalValue.value).maxValue
        }
    }
</script>

<style scoped>

</style>
